package com.sf.fy.uav.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sf.fy.uav.common.response.operational.CallbackSigningRequest;
import com.sf.fy.uav.common.utils.BeanUtil;
import com.sf.fy.uav.common.utils.PhoneEncoderUtil;
import com.sf.fy.uav.entity.SigningCallbackInfo;
import com.sf.fy.uav.mapper.SigningCallbackInfoMapper;
import com.sf.fy.uav.service.ISigningCallbackInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

import java.util.Date;

/**
 * <p>
 * 签约回调信息 服务实现类
 * </p>
 *
 * @author LTQ
 * @since 2023-08-29
 */
@Service
public class SigningCallbackInfoServiceImpl extends ServiceImpl<SigningCallbackInfoMapper, SigningCallbackInfo> implements ISigningCallbackInfoService {

    @Autowired
    private SigningCallbackInfoMapper signingCallbackInfoMapper;

    @Autowired
    private PhoneEncoderUtil phoneEncoderUtil;

    @Override
    public void callbackSigningInfo(CallbackSigningRequest callbackSigningRequest) {
        Date date = new Date();
        SigningCallbackInfo signingCallbackInfo = BeanUtil.copyProperties(callbackSigningRequest, SigningCallbackInfo.class);
        String qkPhone = signingCallbackInfo.getQkPhone();
        String qkId = signingCallbackInfo.getQkId();
        if (!ObjectUtils.isEmpty(qkPhone)) {
            signingCallbackInfo.setQkPhone(phoneEncoderUtil.encryptString(qkPhone));
        }
        if (!ObjectUtils.isEmpty(qkId)) {
            signingCallbackInfo.setQkId(phoneEncoderUtil.encryptString(qkId));
        }
        signingCallbackInfo.setUpdateTime(date);
        signingCallbackInfo.setCreateTime(date);
        signingCallbackInfoMapper.insert(signingCallbackInfo);
    }
}
